
{***********************************************************}
{                                                           }
{      Informix esql "sqlhdr.h"                             }
{                                                           }
{      Translated to Object Pascal by                       }
{      Copyright (c) 2001-2008 Luxena Software Company      }
{      http://www.luxena.com                                }
{      e-mail: support@luxena.com                           }
{                                                           }
{***********************************************************}

unit IfxSqlHdr;

{$I lx.inc}

{$IFDEF VER140_OR_ABOVE}
  {$ALIGN 8}
{$ENDIF}

interface

uses
  LXTypes, IfxTypes, IfxSqlda, IfxSqlca, IfxCollect, IfxLogin;


const

  // CURSOR state when (OPTOFC) Open-Fetch-Close Optimization is being used

  CURSOR_NOT_OPEN = 0;
  CURSOR_USER_OPEN = 1;
  CURSOR_OPEN_FETCH = 2;
  CURSOR_FETCHING = 3;


  // SQL field type codes

  XSQLD = 0;
  XSQLTYPE = 1;
  XSQLLEN = 2;
  XSQLPRECISION = 3;
  XSQLNULLABLE = 4;
  XSQLIND = 5;
  XSQLDATA = 6;
  XSQLNAME = 7;
  XSQLSCALE = 8;
  XSQLILEN = 9;
  XSQLITYPE = 10;
  XSQLIDATA = 11;
  XSQLXID = 12;
  XSQLTYPENAME = 13;
  XSQLTYPELEN = 14;
  XSQLOWNERLEN = 15;
  XSQLOWNERNAME = 16;
  XSQLSOURCETYPE = 17;
  XSQLSOURCEID = 18;


  // Connection type

  IFX_CONN_TYPE_NO_AUTH = $0;
  IFX_CONN_TYPE_USER_AUTH = $1;
  IFX_CONN_TYPE_CRED_AUTH = $2;


  // Types stored in csblock_t (iqutil.c)

  IQ_CURSOR = $0000;
  IQ_STMT = $0001;
  IQ_ALL = $0002;
  IQ_SKIP_CUR_CHK = $0100;
  IQ_SKIP_DOWNSHIFT = $0200;


  // The following defines will be used to check the installed version of
  // the libraries against the ones used during compilation. A handshaking
  // method was introduced with shared libraries to indicate if the
  // API changed between one release of the library to the other.

  IFX_GENLIB_ID = 1;                              // identifier for libgen.so
  IFX_OSLIB_ID = 2;                               // identifier for libos.so
  IFX_SQLILIB_ID = 3;                             // identifier for libsql.so
  IFX_GLSLIB_ID = 4;                              // identifier for libgls.so


  // provide macro definition for the library versions
  // being used while generating client's application executable.

  CLIENT_GEN_VER = 710;                           // libgen.so used for compiling application
  CLIENT_OS_VER = 710;                            // libos.so used for compiling application
  CLIENT_SQLI_VER = 720;                          // libsql.so used for compiling application
  CLIENT_GLS_VER = 710;                           // libgls.so used for compiling application


{$IFDEF IFX_THREAD}

  // defines for dynamic thread functions
  TH_ONCE = 0;
  TH_MUTEXATTR_CREATE = 1;
  TH_MUTEXATTR_SETKIND = 2;
  TH_MUTEXATTR_DELETE = 3;
  TH_MUTEX_INIT = 4;
  TH_MUTEX_DESTROY = 5;
  TH_MUTEX_LOCK = 6;
  TH_MUTEX_UNLOCK = 7;
  TH_MUTEX_TRYLOCK = 8;
  TH_CONDATTR_CREATE = 9;
  TH_CONDATTR_DELETE = 10;
  TH_COND_INIT = 11;
  TH_COND_DESTROY = 12;
  TH_COND_TIMEDWAIT = 13;
  TH_KEYCREATE = 14;
  TH_GETSPECIFIC = 15;
  TH_SETSPECIFIC = 16;
  TH_SELF = 17;

  // Number of dynamic thread functions;
  TH_MAXIMUM = 18;

{$ENDIF}                                          // IFX_THREAD

  // defines for SqlFreeMem, FreeType
  CURSOR_FREE = 1;
  STRING_FREE = 2;
  SQLDA_FREE = 3;
  CONN_FREE = 4;


type

  PIfx_squlist = ^TIfx_squlist;

  _ifx_squlist = record
    _SQUulist: PPChar;                            // columns to be updated
    _SQUnext: PIfx_squlist;                       // next update list  //* P_squlist was replaced by PIfx_squlist
    _SQUid: mint;                                 // update list id
  end;

  TIfx_squlist = _ifx_squlist;



  PIfx_cursor = ^TIfx_cursor;

  _ifx_cursor = record
    _SQCcursptr: PIfx_cursor;                     // pointer to the statement/cursor block.
    _SQCstmttype: int2;                           // SQ_SELECT, SQ_INSERT, etc.
    _SQCsqlid: int2;                              // SQL's id for this cursor
    _SQCnfields: int2;                            // number of result fields (number supplied by SQL)
    _SQCnibind: int2;                             // number of input args
    _SQCnobind: int2;                             // number of output args
    _SQCnrettype: int2;                           // number of fields sent for the rettype msg
    _SQCtcount: int2;                             // tuples remaining in buffer
    _SQCtsize: int2;                              // length of data expected from SQL
    _SQCtbsize: int4;                             // tuple buffer size
    _SQCflags: int4;                              // CROPEN, CREOF, CRSINGLE ,CRPREPARE

    // used for scroll cursors
    _SQCfirst: int4;                              // rowid of 1st tuple in buffer
    _SQClast: int4;                               // rowid of last tuple in buffer

    _SQCibind: PIfx_sqlvar;                       // pointer to first in array of binding structures for arguments
                                                  // to be taken from the user program and sent to SQL;

    _SQCobind: PIfx_sqlvar;                       // pointer to first in array of binding structures for values
                                                  // to be received from SQL and supplied to the user program;

    _SQCrettype: PIfx_sqlvar;                     // pointer to first in array of binding structure for values
                                                  // to be sent thru the rettype msg

    _SQCfields: PIfx_sqlvar;                      // pointer to first in array of structures describing the data
                                                  // to be received from SQL; (fields described by SQL)

    _SQCsqlda: PIfx_sqlda;                        // pointer to sqlda

    _SQCcommand: PPChar;                          // pointer to ptrs to pieces of the command

    _SQCstrtab: PChar;                            // pointer to table of strings - the names of the attributes to be
                                                  // received from SQL (table supplied by SQL)

    _SQCtbuf: PChar;                              // tuple buffer
    _SQCtuple: PChar;                             // pointer to current tuple within buffer
    _SQCname: PChar;                              // cursor name
    _SQCapiname: PChar;                           // column name buffer when DBAPICODE is set

    _SQCposition: mint;                           // Used only for INSERT AT stmts
    _SQCiscollstmt: mint;                         // Set if cursor or stmt is for collection table
    _SQCcl_putcnt: mint;                          // Number of variable length rows inserted using an insert cursor.

    _SQCcollection: PIfx_collection;              // pointer to collection var
    _SQCcollcur: TIfx_coll_cur;                   // collection manager cursor block
    _SQCcl_tupleinfo: PIfx_cl_tupinfo;            // collection tuple information
    _SQClitvalues: PIfx_literal;                  // pointer to the input values specified for the collection table
    _SQC_savlitvalues: PIfx_literal;              // pointer to the saved literal values that have
    // the QMARKBIND entries in it

    _SQCnamelist: PIfx_namelist;                  // Pointer to column names specified in the projection
                                                  // list for SELECT, UPDATE, INSERT and DELETE

    _SQCcl_num: int2;                             // number of collection columns

    // the following 4 fields are for open-fetch-close optimization
    _SQCopen_state: int2;                         // see open_state below
    _SQCdesc_name: PChar;                         // saved sql desc name
    _SQCidesc: PIfx_sqlda;                        // saved idesc value
    _SQCreopt: int2;                              // saved reoptimization flag

    _SQCcls: Pointer;                             // reserved for fast path
    _SQCcur7: Pointer;                            // points to the corresponding 7.x cursor structure
    _SQCflags3: int4;                             // reserved flag for future use
    _SQCreserved: Pointer;                        // reserved for future use
  end;

  TIfx_cursor = _ifx_cursor;


  _ifx_statement = record
    _SQSstmttype: int2;                           // SQ_SELECT, SQ_INSERT, etc.
    _SQSsqlid: int2;                              // SQL's id for this cursor
    _SQSreserved: Pointer;                        // reserved for future use
  end;
  PIfx_Statement = ^TIfx_Statement;
  TIfx_Statement = _ifx_statement;


  _ifx_hostvar = record
    hostaddr: PChar;                              // address of host variable
    fieldtype: int2;                              // field entry requested by GET
    hosttype: int2;                               // host type
    hostlen: int4;                                // length of field type
    qualifier: int2;                              // qualifier for DATETIME/INTERVAL
    btname: PChar;                                // Base type name if provided in host variable declaration
    btownername: PChar;                           // Base type owner name
    cstr: PChar;                                  // Collection or row host string
    reserved: Pointer;                            // reserved for future use
  end;
  PIfx_HostVar = ^TIfx_HostVar;
  TIfx_hostvar = _ifx_hostvar;



  // Specifications for FETCH

  _fetchspec = record
    fval: int4;                                   // scroll quantity
    fdir: mint;                                   // direction of FETCH (NEXT, PREVIOUS..)
    findchk: mint;                                // check for indicator?
  end;
  P_FetchSpec = ^T_FetchSpec;
  T_FetchSpec = _fetchspec;



  // User connection structure

  ifx_user_struct = record
    name: PChar;
    password: PChar;
  end;
  TIfx_user = ifx_user_struct;


  // ASF connection structure

  ifx_connect_struct = record
    conn_type: int2;                              // connection type
    conn_cred_hdl: Pointer;                       // connection credential handle could be pointer to ifx_user_t or any CSS supported credentials
  end;
  PPIfx_Conn = ^PIfx_Conn;
  PIfx_Conn = ^TIfx_Conn;
  TIfx_Conn = ifx_connect_struct;




{$IFDEF IFX_THREAD}
  TFuncPtr = function: mulong;
  TIfxOS_set_thrfunc = function(func: mint; Param: TFuncPtr): mint;
{$ENDIF}                                          // IFX_THREAD



  // This global variable FetBufSize (Fetch Buffer Size) will allow
  // the application to over-ride cursor->_SQCtbsize which dictates the
  // size of the buffer that holds the data that the BE will fill.


  Tfnsqlcode = function: PInt4;

  // char   ( *(fnsqlstate()))[6];
  PSQLSTATE = ^TSQLSTATE;
  TSQLSTATE = array[0..5] of Char;
  Tfnsqlstate = function: PSQLSTATE;

  // struct sqlca_s *(fnsqlca());
  Tfnsqlca = function: PIfx_sqlca;

  // struct LoginInfoStructTag *(fninetlogin());
  Tfninetlogin = function: PLoginInfoStructTag;

  // int2 *(fnFetArrSize());
  TfnFetArrSize = function: PInt2;

  //int2 *(fnFetBufSize());
  TfnFetBufSize = function: PInt2;

  //int2 *(fnOptMsg());
  TfnOptMsg = function: PInt2;

  //int *(fndbfltprec());
  Tfndbfltprec = function: PInteger;


implementation

end.